<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/view/include/css-include.jsp"%>
<%@ include file="/view/include/jsp-include.jsp"%>
<%@ include file="/view/include/jquery-include.jsp"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page import="main.java.tmi.authority.service.RoleVO, java.util.HashMap" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Authority Update</title>

<script type="text/javascript">

    $().ready(function() {
        view();

         /* 저장버튼 */
        $("#saveBtn").bind("click",function(){       
            $("form[name='authorityUpdateFrm']").submit();
        });

        $("#onList").bind("click",function(){
            location="/authority.html";            
        });

        /* 메인폼 서브밋 */
        $("form[name='authorityUpdateFrm']").ajaxForm({
            dataType: "json",
            beforeSerialize: function($form, options) {
                //return $("form[name='orderFrm']").valid();  jquery 벨류데이션 플러그인 사용시
                 if( !validation() ){       //화면 항목 점검 시작
                    return false;
                }
            },
            success:function(data) {
               if(data.result == true){
                   alert("Saved.....!");
                   location="/authority.html";    
               }               
           },
           error:function(){alert("ERROR!");}
        }); 
    });

    /* 조회 펑션 */
    function view(){
        $.post(
                '/getAuthorityDetailView.json', {
                userId : $("#userId").val()
                },
            function(data) {
                //reSetValidete(); //벨류데이션 초기화
                
                searchDataMaping(data);    //DATA맵핑 
            });
    }

    /* searchData 맵핑 */
    function searchDataMaping(data){
        var val = ""; 
        for(var v in data.resultDetailMap) {       //상단 조회 결과 맵핑 조회return값이 한건임
            $("#"+v).val(data.resultDetailMap[v]);
        }        
    }

    function validation(){

        var userId     = $("#userId").val();
        var roleId     = $("#roleId").val();
        
        if(userId==null     || userId=="") {   alert("User Id required!!"); $("#userId").focus(); return false; }
        if(roleId==null    || roleId=="") { alert("Role Id required!!"); $("#roleId").focus(); return false; }

      return true;      
    } 
    
</script>
</head>
<body>
<div class="wrap">
    <form name="authorityUpdateFrm" method="post" action="/saveAuthority.json">
    <div class="pagetitle">
        <h1>AUTH LIST / UPDATE</h1>
    </div>
    <div class="">
        <table class="TableST">
            <tr>
                <th>User Id</th>
                <td><input type="text" class="inSTR" size="80" name="userId" id="userId" value="${userId}"/></td>
            </tr>    
            <tr>
                <th>User Name</th>
                <td><input type="text" class="inSTR" size="80" name="userName" id="userName"/></td>
            </tr>                 
            <tr>
                <th>Role</th>
                <td>
                    <select name="roleId" id="roleId">
                        <c:forEach var="role" items="${roles}"><option value="${role.roleId}">${role.roleName}</option></c:forEach> 
                    </select>
                </td>
            </tr>          
         </table>
    </div>
    <div class="bo_btn">
        <ul class="btnst"><li class="a"><a href="#" id="onList" >LIST</a></li></ul>
        <ul class="btnst"><li class="a"><a href="#" id="saveBtn" >SAVE</a></li></ul>
    </div>
    <input type="hidden" name="saveStatus" id="saveStatus" value="UPDATE"/>
    </form>
</div>
</body>
</html>